// app.js
import WebSocketClient from './utils/websocket';

App({
  globalData: {
    userInfo: null,
    wsClient: null
  },

  onLaunch() {
    // 初始化WebSocket
    this.initWebSocket();
  },

  initWebSocket() {
    const token = wx.getStorageSync('token');
    if (!token) {
      console.log('未登录，不创建WebSocket连接');
      return;
    }

    // 创建WebSocket客户端实例
    const wsClient = new WebSocketClient('ws://localhost:8080/ws/notification');
    wsClient.setToken(token);
    wsClient.connect();

    this.globalData.wsClient = wsClient;
  }
});
